# -*- coding: utf-8 -*-

import os
import wx
import WbEditPanel

__all__ = ['create']

def create(parent=None, file=""):
    return WbEditDialog(parent, file)

[wxID_DIALOG1
] = [wx.NewId() for _init_ctrls in range(1)]

class WbEditDialog(wx.Dialog):
    def _init_coll_boxSizer3_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.button1, 0, border=5, flag=wx.ALL)
        parent.AddWindow(self.button2, 0, border=5, flag=wx.ALL)

    def _init_coll_boxSizer4_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.ep, 0, border=0, flag=0)

    def _init_coll_boxSizer2_Items(self, parent):
        # generated method, don't edit

        parent.AddSizer(self.boxSizer4, 0, border=10, flag=wx.ALL)
        parent.AddSizer(self.boxSizer3, 0, border=5, flag=wx.ALL|wx.ALIGN_RIGHT)

    def _init_sizers(self):
        # generated method, don't edit

        self.boxSizer2 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer3 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer4 = wx.StaticBoxSizer(self.box)

        self._init_coll_boxSizer2_Items(self.boxSizer2)
        self._init_coll_boxSizer3_Items(self.boxSizer3)
        self._init_coll_boxSizer4_Items(self.boxSizer4)

        self.SetSizer(self.boxSizer2)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              style=wx.DEFAULT_DIALOG_STYLE, title='Modify Dialog')
        self.SetTitle("Dialog - %s" % os.path.basename(self.file))

        self.button1 = wx.Button(self, wx.ID_OK) # _("Save(&S)"))
        #self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button)

        self.button2 = wx.Button(self, wx.ID_CANCEL)
        #self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button)

        self.ep = WbEditPanel.create(self, self.file)

        self.box = wx.StaticBox(self, -1, _("Modify File Attributes"))

        self._init_sizers()
        self.Fit()

    def __init__(self, parent, file):
        self.file = file
        self._init_ctrls(parent)
    
    def setFileAttrs(self):
        if not file:
            return False
        ctime = self.ep.dtpc.getPyTime()
        mtime = self.ep.dtpm.getPyTime()
        atime = self.ep.dtpa.getPyTime()
        setFileAttributes(self.file, (ctime, mtime, atime))
        return True

def setFileAttributes(file_name, attrs):
    """
    file_name - File name
    attrs - [ctime, mtime, atime]
    """
    (ctime, mtime, atime) = attrs
    import win32file
    filehandle = win32file.CreateFile(file_name, win32file.GENERIC_WRITE, 
            0, None, win32file.OPEN_EXISTING, 0, 0)
    win32file.SetFileTime(filehandle, ctime, atime, mtime)
    filehandle.Close()
    

def Test(file):
    app = wx.PySimpleApp()
    app.MainLoop()
    dlg = WbEditDialog(None, file)
    dlg.CenterOnScreen()
    val = dlg.ShowModal()
    if val == wx.ID_OK:
        dlg.setFileAttrs()
    else:
        print 'Close'
    dlg.Destroy()

if __name__ == '__main__':
    from Main import installwxgettext
    installwxgettext()
    file = '1.txt'
    Test(file)
